home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / areuh.tar / areuh / assembler / mdep.c < prev    next >
C/C++ Source or Header  |  1990-10-10  |  6KB  |  327 lines

  1. /*
  2.  * Authors :
  3.  *   Pierre DAVID (pda@masi.ibp.fr or pda@frunip62.bitnet)
  4.  *   Janick TAILLANDIER
  5.  *
  6.  * This program can be freely used or distributed as long as this
  7.  * note is kept.
  8.  *
  9.  * This program is provided "as is".
  10.  */
  11.  
  12. /******************************************************************************
  13.  
  14.       M A C H I N E    D E P E N D E N C I E S
  15.  
  16. ******************************************************************************/
  17.  
  18. #include "flag.h"
  19.  
  20. #if ASSEMBLER
  21. #include "aglobal.h"
  22. #else
  23. #include "lglobal.h"
  24. #endif
  25.  
  26. extern struct symbol *add_label() ;
  27.  
  28. #if HPUX
  29.  
  30. void format_time (str)
  31. uchar *str ;
  32. {
  33.     long int l ;
  34.  
  35.     extern long int time () ;
  36.     extern char *ctime () ;
  37.  
  38.     l = time (0L) ;
  39.     strcpy (str, ctime (&l)) ;
  40.     str [strlen (str) - 1] = EOL ;
  41. }
  42.  
  43. char *tab[] = { "",
  44.         "/usr/lib/",
  45.         "/usr/local/lib/",
  46.         "/lib/",
  47.         "/hp71/lib/",
  48.         "/local/lib/",
  49.         0 } ;
  50.  
  51. void load_file (file)
  52. uchar *file ;
  53. {
  54.     int i = 0 ;
  55.     uchar name [MAXLEN+1] ;
  56.     saddr val ;
  57.     FILE *fp ;
  58.  
  59.     fp = (FILE *) NULL ;
  60.     while ((tab[i])&&(!fp))
  61.     {
  62.     sprintf (name, "%s%s", tab[i++], file) ;
  63.     fp = fopen (name, "r") ;
  64.     }
  65.     if (!fp) error (ERROPN, file) ;
  66.  
  67. #if LINKER
  68.     file = 0 ;
  69. #endif
  70.     while (fscanf (fp, "%s\n%X\n", name, &val) != EOF)
  71.     {
  72. #if ASSEMBLER
  73.     add_label (name, val, "", LABS, 1) ;
  74. #else
  75.     add_label (name, val, 1) ;
  76. #endif
  77.     }
  78.     if (ferror (fp)) error (ERRWRT, file) ;
  79.     if (fclose (fp)) error (ERRCLO, file) ;
  80. }
  81.  
  82. #include <sys/types.h>
  83. #include <sys/stat.h>
  84.  
  85. /* look for object file (object code or listing file)
  86.  *   if non existent, ok
  87.  *   if exists and not directory, ok
  88.  *   if exists and directory, then append "<dir>/<default>" */
  89.  
  90. look_obj (fname, dfl)
  91. uchar *fname, *dfl ;
  92. {
  93.     struct stat buf ;
  94.  
  95.     if (*fname == EOL)           /* if fname == "" then default it */
  96.     strcpy (fname, dfl) ;
  97.  
  98.     if (!stat (fname, &buf))       /* file exists. Is it a directory ? */
  99.     {
  100.     if ((buf.st_mode & S_IFMT) == S_IFDIR)
  101.         sprintf (fname, "%s/%s", fname, dfl) ;
  102.     }
  103. }
  104.  
  105. /* build a default file name, based on "source" basename and a given
  106.  * default extension.
  107.  */
  108.  
  109. dfl_extension (object, source, extension)
  110. uchar *object, *source, *extension ;
  111. {
  112.     uchar *pname ;
  113.  
  114.     strcpy (object, source) ;
  115.     pname = object ;
  116.     while ((*pname)&&(*pname!='.')) pname++ ;
  117.     if (*pname==EOL) *pname = '.' ;
  118.     strcpy (pname+1, extension) ;
  119. }
  120.  
  121. #endif       /* HPUX */
  122.  
  123.  
  124. #if ATARI_LATTICE
  125.  
  126. char skipvar ;
  127.  
  128. void format_time (str)
  129. uchar *str ;
  130. {
  131.     strcpy (str, "Areuh Tagada Bouzouh bouzouh areuh areuh... et toc !") ;
  132. }
  133.  
  134. char *optarg ;
  135. int optind = 0, opterr = 0 ;
  136.  
  137. int getopt (argc, argv, optstr)
  138. int argc ;
  139. char *argv[], *optstr ;
  140. {
  141.     char *o, car ;
  142.     static char *index = 0 ;
  143.     extern char *strchr () ;
  144.  
  145.     if ((index==(char *)0)||(*(index+1)==0))
  146.     {
  147.     if (++optind>argc-1) return (EOF) ;
  148.     index = argv[optind] ;
  149.     if (*index!='-') return (EOF) ;
  150.     }
  151.     car = *(++index) ;          /* state 6 */
  152.     if (!(o = strchr (optstr, car))) return ('?') ;
  153.     if (*(o+1)!=':')     return ((int) car) ;
  154.     if (*(index+1)) optarg = index+1 ;
  155.     else
  156.     {
  157.     if (++optind>argc-1) return (EOF) ;
  158.     else optarg = argv[optind] ;
  159.     }
  160.     index = (char *) 0 ;
  161.     return ((int) car) ;
  162. }
  163.  
  164. uchar *tab[] = { "",
  165.          "A:",
  166.          "A:\\TABLE\\",
  167.          0 } ;
  168.  
  169. void load_file (file)
  170. uchar *file ;
  171. {
  172.     int i = 0 ;
  173.     uchar name [MAXLEN+1] ;
  174.     saddr val ;
  175.     FILE *fp ;
  176.  
  177.     fp = (FILE *) NULL ;
  178.     while ((tab[i])&&(!fp))
  179.     {
  180.     sprintf (name, "%s%s", tab[i++], file) ;
  181.     fp = fopen (name, "r") ;
  182.     }
  183.     if (!fp) error (ERROPN, file) ;
  184.  
  185. #if LINKER
  186.     file = 0 ;
  187. #endif
  188.     while (fscanf (fp, "%s\n%x\n", name, &val) != EOF)
  189.     {
  190. #if ASSEMBLER
  191.     add_label (name, val, "", LABS, 1) ;
  192. #else
  193.     add_label (name, val, 1) ;
  194. #endif
  195.     }
  196.     if (fclose (fp)) error (ERRCLO, file) ;
  197. }
  198.  
  199. #endif      /* ATARI_LATTICE */
  200.  
  201.  
  202. #if PC_MSC
  203.  
  204. char skipvar ;
  205.  
  206. void format_time (str)
  207. uchar *str ;
  208. {
  209.     long int l ;
  210.  
  211.     extern long int time () ;
  212.     extern char *ctime () ;
  213.  
  214.     time (&l) ;
  215.     strcpy (str, ctime (&l)) ;
  216.     str [strlen (str) - 1] = EOL ;
  217. }
  218.  
  219. char *optarg ;
  220. int optind = 0, opterr = 0 ;
  221.  
  222. int getopt (argc, argv, optstr)
  223. int argc ;
  224. char *argv[], *optstr ;
  225. {
  226.     char *o, car ;
  227.     static char *index = 0 ;
  228.     extern char *strchr () ;
  229.  
  230.     if ((index==(char *)0)||(*(index+1)==0))
  231.     {
  232.     if (++optind>argc-1) return (EOF) ;
  233.     index = argv[optind] ;
  234.     if (*index!='-') return (EOF) ;
  235.     }
  236.     car = *(++index) ;          /* state 6 */
  237.     if (!(o = strchr (optstr, car))) return ('?') ;
  238.     if (*(o+1)!=':')     return ((int) car) ;
  239.     if (*(index+1)) optarg = index+1 ;
  240.     else
  241.     {
  242.     if (++optind>argc-1) return (EOF) ;
  243.     else optarg = argv[optind] ;
  244.     }
  245.     index = (char *) 0 ;
  246.     return ((int) car) ;
  247. }
  248.  
  249. uchar *tab[] = { "",
  250.          "c:",
  251.          "c:\\hp71\\",
  252.          "c:\\lib\\hp71\\",
  253.          "c:\\lib\\",
  254.          "c:\\areuh\\lib\\",
  255.          0 } ;
  256.  
  257. void load_file (file)
  258. uchar *file ;
  259. {
  260.     int i = 0 ;
  261.     uchar name [MAXLEN+1] ;
  262.     saddr val ;
  263.     FILE *fp ;
  264.  
  265.     fp = (FILE *) NULL ;
  266.     while ((tab[i])&&(!fp))
  267.     {
  268.     sprintf (name, "%s%s", tab[i++], file) ;
  269.     fp = fopen (name, "r") ;
  270.     }
  271.     if (!fp) error (ERROPN, file) ;
  272.  
  273. #if LINKER
  274.     file = 0 ;
  275. #endif
  276.     while (fscanf (fp, "%s\n%X\n", name, &val) != EOF)
  277.     {
  278. #if ASSEMBLER
  279.     add_label (name, val, "", LABS, 1) ;
  280. #else
  281.     add_label (name, val, 1) ;
  282. #endif
  283.     }
  284.     if (fclose (fp)) error (ERRCLO, file) ;
  285. }
  286.  
  287. #include <sys\types.h>
  288. #include <sys\stat.h>
  289.  
  290. /* look for object file (object code or listing file)
  291.  *   if non existent, ok
  292.  *   if exists and not directory, ok
  293.  *   if exists and directory, then append "<dir>/<default>" */
  294.  
  295. look_obj (fname, dfl)
  296. uchar *fname, *dfl ;
  297. {
  298.     struct stat buf ;
  299.  
  300.     if (*fname == EOL)           /* if fname == "" then default it */
  301.     strcpy (fname, dfl) ;
  302.  
  303.     if (!stat (fname, &buf))       /* file exists. Is it a directory ? */
  304.     {
  305.     if ((buf.st_mode & S_IFMT) == S_IFDIR)
  306.         sprintf (fname, "%s\\%s", fname, dfl) ;
  307.     }
  308. }
  309.  
  310. /* build a default file name, based on "source" basename and a given
  311.  * default extension.
  312.  */
  313.  
  314. dfl_extension (object, source, extension)
  315. uchar *object, *source, *extension ;
  316. {
  317.     uchar *pname ;
  318.  
  319.     strcpy (object, source) ;
  320.     pname = object ;
  321.     while ((*pname)&&(*pname!='.')) pname++ ;
  322.     if (*pname==EOL) *pname = '.' ;
  323.     strcpy (pname+1, extension) ;
  324. }
  325.  
  326. #endif      /* PC_MSC */
  327.